package com.one.group.admin.listener;

import com.one.group.admin.emailtool.SendEmail;
import com.one.group.admin.service.impl.SpBillServiceImpl;
import com.one.group.model.dto.SpBillAddTestDto;
import com.one.group.model.dto.SpSendEmailDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class emailListener {
    @Autowired
    private SendEmail sendEmail;
    /**
     * 监听邮件消息
     * @param spSendEmailDto 邮件信息
     */
    @RabbitListener(bindings = @QueueBinding(value = @Queue(name = "direct.queue2"),
            exchange = @Exchange(name = "gxa.direct"), key = {"sendEmail"}))
    public void listenerDirectQueue1Message(SpSendEmailDto spSendEmailDto) {
        log.info("监听到消息：{}", spSendEmailDto);
        if(!sendEmail.sendEmail(spSendEmailDto)){
            log.info("发送邮件失败");
        }
        else log.info("发送邮件成功");
    }
}
